<template>
  <div id="testlist">
    <el-dialog
      :title="dialogtitle"
      :visible.sync="porjectEidtFormVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <div id="trainEditTable">
        <el-form :model="addForm" :rules="addFormRules" ref="addForm" label-width="150px" @submit.native.prevent>
          <el-form-item label="司内会议名称" prop="name">
            <el-input v-model="addForm.name" auto-complete="off" style="width:300px;" :maxlength="50" @keyup.enter.native="addFormSubmit"></el-input>
          </el-form-item>
          <el-form-item label="" >
            <el-button type="primary" :loading="addLoading" @click="addFormSubmit">保存</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/meeting' }">司内会议</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <el-form :inline="true" :model="filters">
        <div>
          <el-form-item label="司内会议名称">
            <el-input v-model="filters.key" placeholder="关键字" @keyup.enter.native="searchPrj"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchMeeting" icon="el-icon-search">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="success" @click="addnew" icon="el-icon-plus" v-if="meetingAdmin">新建</el-button>
          </el-form-item>
        </div>
      </el-form>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <h1>司内会议列表</h1>
      <el-table :data="prjs" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border>
        <el-table-column type="index" label=" " width="50" fixed align="center" class-name="tableth">
        </el-table-column>
        <el-table-column prop="name" label="司内会议名称" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="创建时间" width="170" prop="dataCreateDatetime">
          <template slot-scope="scope">
            {{dateFtt("yyyy-MM-dd hh:mm:ss",scope.row.dataCreateDatetime)}}
          </template>
        </el-table-column>
        <el-table-column label="状态" width="100" align="center" v-if="meetingAdmin">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status===1" type="success" effect="dark" style="cursor:pointer;margin:5px 0" title="点击停用此任务" @click="setStatus(scope.row.id,0)">启用</el-tag>
            <el-tag v-else type="info" effect="dark" style="cursor:pointer;margin:5px 0" title="点击启用此任务" @click="setStatus(scope.row.id,1)">停用</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="350">
          <template slot-scope="scope">
            <el-button size="small" style="margin:10px 0" @click="showList(scope.row.id)" type="primary" v-if="meetingAdmin" icon="el-icon-search">查看</el-button>

            <el-dropdown split-button type="success" @click="itemList(scope.row.id)" v-if="meetingAdmin" size="small">
              <i class="el-icon-edit"></i> 管理
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(scope.row.id,scope.row.name)" >修改</el-dropdown-item>
                <el-dropdown-item @click.native="removeMeeting(scope.row.id)" >删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

            <!-- <el-button size="small" style="margin:10px 0" @click="itemList(scope.row.id)" type="success" icon="el-icon-edit" v-if="meetingAdmin">管理</el-button>
            <el-dropdown v-if="meetingAdmin" style="margin-left:5px">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(scope.row.id,scope.row.name)" >修改</el-dropdown-item>
                <el-dropdown-item v-if="scope.row.status!==1" @click.native="removeMeeting(scope.row.id)" >删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown> -->

            <el-button size="small" style="margin:10px 0" v-if="scope.row.status===1" @click="myList(scope.row.id)" icon="el-icon-s-order">填报</el-button>
          </template>
        </el-table-column>
      </el-table>
    <div class="block">
      <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    </div>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      meetingAdmin: false,
      prjs: [],
      projectId: null,
      dialogtitle: '新建',
      timestamp: '',
      porjectEidtFormVisible: false,
      porjectEidtFormLoading: false,
      addForm: {
        id: null,
        name: ''
      },
      addFormRules: {
        name: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      },
      addLoading: false,
      filters: {
        key: ''
      },
      total: 0,
      pageNum: 1,
      pageSize: 20,
      listLoading: false,
      totalnum: 0,
      Isace: true,
      Sortkey: '',
      changeSizeFlag: false,
      tableHeight: 100,
      statusdic: [],
      myloading: false,
      myname: ''
    }
  },
  methods: {
    itemList (id) {
      this.$router.push('/meeting/list/' + id)
    },
    myList (id) {
      this.$router.push('/meeting/deptlist/' + id)
    },
    showList (id) {
      this.$router.push('/meeting/showlist/' + id)
    },
    handleEdit (id, name) {
      this.addForm.id = id
      this.addForm.name = name
      this.dialogtitle = '修改'
      this.porjectEidtFormVisible = true
    },
    addFormSubmit () {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.addLoading = true
          let para = {
            id: this.addForm.id,
            name: this.addForm.name
          }
          this.$http.post(this.$http.defaults.meetingAPI + `api/meetingBusTask/save`, para).then(response => {
            console.log(response.data.success)
            if (response.data.success === true) {
              this.$message({
                message: '保存成功',
                type: 'success'
              })
              this.$refs['addForm'].resetFields()
              this.porjectEidtFormVisible = false
              this.addLoading = false
              this.getPrj()
            } else {
              console.log('保存失败:' + response.data.message)
              this.$message({
                message: '保存失败:' + response.data.message,
                type: 'error'
              })
              this.addLoading = false
            }
          }).catch(function (error) {
            console.log(error)
            this.$message({
              message: '保存失败:' + error,
              type: 'error'
            })
            this.addLoading = false
          })
        }
      })
    },
    addnew () {
      this.addForm.id = null
      this.addForm.name = ''
      this.porjectEidtFormVisible = true
      this.dialogtitle = '新建'
    },
    setStatus (id, flag) {
      let flagtext = '启用'
      let type = 'success'
      if (flag === 0) {
        flagtext = '停用'
        type = 'error'
      }
      this.$confirm('确定' + flagtext + '该任务?', '提示', {
        type: type
      }).then(() => {
        this.myloading = true
        let para = {
          id: id,
          status: flag
        }
        this.$http.post(this.$http.defaults.meetingAPI + `api/meetingBusTask/updateStatus`, para).then(response => {
          if (response.data.success === true) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          } else {
            console.log('操作失败:' + response.data.message)
            this.$message({
              message: '操作失败:' + response.data.message,
              type: 'error'
            })
          }
          this.myloading = false
          this.getPrj()
        })
      })
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getPrj()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getPrj()
      }
    },
    // 查询
    searchMeeting () {
      this.pageNum = 1
      this.getPrj()
    },
    getPrj () {
      let para = {
        name: this.filters.key,
        status: this.meetingAdmin ? null : 1,
        orderField: this.Sortkey,
        orderType: this.Isace,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(this.$http.defaults.meetingAPI + `api/meetingBusTask/queryByPage`, para)
        .then(response => {
          this.listLoading = false
          this.prjs = response.data.result.records
          this.totalnum = response.data.result.total
          this.changeSizeFlag = false
        })
        .catch(error => {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    removeMeeting (id) {
      this.$confirm('确认删除该司内会议吗?', '提示', {
        type: 'error'
      }).then(() => {
        this.$http.post(this.$http.defaults.meetingAPI + `api/meetingBusTask/remove`, {ids: [id]}).then(response => {
          if (response.data.success === true) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            console.log('删除失败:' + response.data.message)
            this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
          this.getPrj()
        })
      }).catch(() => {
      })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 292
      })
    },
    getMeetingAuth () {
      this.meetingAdmin = this.inRoles('ROLE_meeting')
      // this.meetingAdmin = true
    },
    inRoles (str) {
      let arr = JSON.parse(localStorage.getItem('Roles'))
      // arr = 'aaabbROLE_admin'
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    }
  },
  mounted () {
    this.getMeetingAuth()
    this.getPrj()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  .el-table--border th, .el-table--border td {
    border-right: 1px solid #95B8E7;
  }
  .el-table th.is-leaf, .el-table td {
    border-bottom: 1px solid #95B8E7;
  }

</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
